<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Welcome extends Controller
{

    public function action_index()
    {
        $contenido = View::factory('index');
        $this->response->body($contenido);
    }

    public function action_home()
    {
        if ($this->request->is_ajax()) {
            $contenido = View::factory('home');
            $this->response->body($contenido);
        }
    }


    public function action_material()
    {
        if ($this->request->is_ajax()) {
            $contenido = View::factory('material');
            $this->response->body($contenido);
        }
    }

    public function action_nosotros()
    {
        if ($this->request->is_ajax()) {
            $contenido = View::factory('nosotros');
            $this->response->body($contenido);
        }
    }

    public function action_proyectos()
    {
        if ($this->request->is_ajax()) {
            $contenido = View::factory('proyectos');
            $this->response->body($contenido);
        }
    }


    public function action_tecnology()
    {
        if ($this->request->is_ajax()) {
            $contenido = View::factory('tecnology');
            $this->response->body($contenido);
        }
    }

    public function action_contacto()
    {
        if ($this->request->is_ajax()) {
            if ($this->request->method() == "POST") {
                try {
                    Email::factory($this->request->post('asunto'), $this->request->post('mensaje'))
                        ->from($this->request->post('email'))
                        ->to('eyscode@gmail.com')
                        ->send();
                    $contenido = View::factory('correcto');
                }
                catch (Exception $e) {
                    $contenido = View::factory('contactanos')
                        ->set('error', 'Uno o más datos son incorrectos');
                }

            } else {
                $contenido = View::factory('contactanos');
            }
        }

        $this->response->body($contenido);
    }

}